package com.itheima.web;

import com.itheima.cst.SysConst;
import com.itheima.dto.OrderDto;
import com.itheima.entity.Result;
import com.itheima.service.OrderService;
import com.itheima.utils.RedisUtil;
import com.itheima.utils.SMSUtil;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendSmsCode/{telphone}")
    public Result sendSmsCode(@PathVariable("telphone") String telphone){
//        rabbitTemplate.convertAndSend("sms_exchange","sms",telphone);
        String code = SMSUtil.generatorCode(4);
        System.out.println("验证码:" + code);
        RedisUtil.set(SysConst.SMS_VALIFYCODE + telphone,code,5);
        return new Result(true);
    }

    @PostMapping("/appo")
    public Result appoOrder(@RequestBody OrderDto orderDto){
        return new Result(orderService.appoOrder(orderDto));
    }

    @GetMapping("/getOrderInfo/{orderId}")
    public Result getOrderInfo(@PathVariable("orderId") Long orderId){
        return new Result(orderService.getOrderInfo(orderId));
    }

}
